<?php require_once('../Connections/locale.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE categorie SET descrizione_categoria=%s, numeri_extra=%s WHERE id_categoria=%s",
                       GetSQLValueString($_POST['descrizione_categoria'], "text"),
                       GetSQLValueString($_POST['numeri_extra'], "int"),
                       GetSQLValueString($_POST['id_categoria'], "int"));

  mysql_select_db($database_locale, $locale);
  $Result1 = mysql_query($updateSQL, $locale) or die(mysql_error());

  $updateGoTo = "elenco_categorie.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_categorie = "1";
if (isset($_GET['id_categoria'])) {
  $colname_categorie = (get_magic_quotes_gpc()) ? $_GET['id_categoria'] : addslashes($_GET['id_categoria']);
}
mysql_select_db($database_locale, $locale);
$query_categorie = sprintf("SELECT * FROM categorie WHERE id_categoria = %s", $colname_categorie);
$categorie = mysql_query($query_categorie, $locale) or die(mysql_error());
$row_categorie = mysql_fetch_assoc($categorie);
$totalRows_categorie = mysql_num_rows($categorie);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<fieldset>
<legend>Modifica Categoria</legend>

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="left">
    <tr valign="baseline">
      <td nowrap align="right">Id Categoria:</td>
      <td><?php echo $row_categorie['id_categoria']; ?></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Descrizione:</td>
      <td><input type="text" name="descrizione_categoria" value="<?php echo $row_categorie['descrizione_categoria']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Numeri Extra:      </td>
      <td><select name="numeri_extra" id="numeri_extra">
        <option value="0" <?php if (!(strcmp(0, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>0</option>
        <option value="1" <?php if (!(strcmp(1, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>1</option>
		<option value="2" <?php if (!(strcmp(2, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>2</option>
		<option value="3" <?php if (!(strcmp(3, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>3</option>
		<option value="4" <?php if (!(strcmp(4, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>4</option>
		<option value="5" <?php if (!(strcmp(5, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>5</option>
		<option value="6" <?php if (!(strcmp(6, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>6</option>
		<option value="7" <?php if (!(strcmp(7, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>7</option>
		<option value="8" <?php if (!(strcmp(8, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>8</option>
		<option value="9" <?php if (!(strcmp(9, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>9</option>
		<option value="10" <?php if (!(strcmp(10, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>10</option>
		<option value="11" <?php if (!(strcmp(11, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>11</option>
		<option value="12" <?php if (!(strcmp(12, $row_categorie['numeri_extra']))) {echo "SELECTED";} ?>>12</option>
            </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Salva"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="id_categoria" value="<?php echo $row_categorie['id_categoria']; ?>">
</form>
</fieldset>
<p><a href="elenco_categorie.php">&lt;- Torna a Elenco Categorie</a> </p>
</body>
</html>
<?php
mysql_free_result($categorie);
?>
